package com.ruoyi.lxs.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.lxs.common.jwt.JwtTokenUtils;
import com.ruoyi.lxs.pojo.dto.LoginDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiXingShuai
 * @className LoginController
 * @description: TODO
 * @date 2023年06月01日
 * @version: 1.0
 */
@RestController
@RequestMapping("/lxs")
public class LoginController {

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginDto loginDto){

        if("admin".equals(loginDto.getUserName())
                && "123456".equals(loginDto.getPwd())){
            // 登录校验成功
            String token = JwtTokenUtils.createJwtToken(loginDto.getUserName());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("token",token);
            return AjaxResult.success(jsonObject);
        }
        return AjaxResult.error("登录失败，用户名或密码错误");
    }
}
